﻿#if UNITY_EDITOR
using NPOI.SS.UserModel;
using System.Collections.Generic;
/// <summary>
/// XLSX相关方法
/// </summary>
public partial class ESF_Logic
{
    #region IsValidCSType 是否是有效的CS类型
    /// <summary>
    /// 数据类型映射
    /// Key:ESF_enCS2UnityDataType
    /// Value:ESF_CSharpCodeAttribute
    /// </summary>
    readonly static Dictionary<string, ESF_CSharpCodeAttribute> mMaping_csType2_ESF_CSharpCodeAttribute =
        typeof(ESF_enCS2UnityDataType).ESF_SpecialValueToSpecialValue<string, ESF_CSharpCodeAttribute, ESF_CSharpCodeAttribute>((a) => { return a.csType.ToLower(); }, (a) => { return a; });

    /// <summary>
    /// 数据类型映射
    /// Key:ESF_enCS2UnityDataType
    /// Value:ESF_CSharpCodeAttribute
    /// </summary>
    readonly static Dictionary<string, ESF_enCS2UnityDataType> mMaping_csType2_ESF_enCS2UnityDataType =
        typeof(ESF_enCS2UnityDataType).ESF_SpecialValueToEnum<string, ESF_CSharpCodeAttribute, ESF_enCS2UnityDataType>((e, a) => { return a.csType.ToLower(); });

    /// <summary>
    /// 指定Row是否包含任意列
    /// </summary>
    /// <param name="_cell">cs类型</param>
    /// <returns>true:包含列,false:不包含列</returns>
    public static bool HasAnyCell(IRow _row)
    {
        bool result = _row != null && _row.Cells != null && _row.Cells.Count > 0;
        if (result)
        {
            result = false;
            foreach (ICell cell in _row.Cells)
            {
                result |= cell != null && !string.IsNullOrEmpty(cell.ToString().Trim());
            }
        }
        return result;
    }

    /// <summary>
    /// 获得CS数据类型列枚举
    /// </summary>
    /// <param name="_cell">CS数据类型列</param>
    /// <returns>CS数据类型枚举</returns>
    public static ESF_enCS2UnityDataType GetCSDataType(ICell _cell)
    {
        return GetCSDataType((_cell == null || string.IsNullOrEmpty(_cell.ToString())) ? string.Empty : _cell.ToString().Trim());
    }

    /// <summary>
    /// 获得CS数据类型枚举
    /// </summary>
    /// <param name="_csType">CS数据类型</param>
    /// <returns>CS数据类型枚举</returns>
    public static ESF_enCS2UnityDataType GetCSDataType(string _csType)
    {
        _csType = _csType.ToLower();
        return mMaping_csType2_ESF_enCS2UnityDataType.ContainsKey(_csType) ? mMaping_csType2_ESF_enCS2UnityDataType[_csType] : ESF_enCS2UnityDataType.String;
    }

    /// <summary>
    /// 指定cs类型列是否是有效的CS类型
    /// </summary>
    /// <param name="_cell">cs类型列</param>
    /// <returns>true:有效的,false:无效的</returns>
    public static bool IsValidCSType(ICell _cell)
    {
        return _cell != null ? IsValidCSType(_cell.ToString()) : false;
    }

    /// <summary>
    /// 指定cs类型是否是有效的CS类型
    /// </summary>
    /// <param name="_csType">cs类型</param>
    /// <returns>true:有效的,false:无效的</returns>
    public static bool IsValidCSType(string _csType)
    {
        _csType = _csType.ToLower();
        return string.IsNullOrEmpty(_csType.Trim()) ? false : mMaping_csType2_ESF_CSharpCodeAttribute.ContainsKey(_csType.Trim().ToLower());
    }
    #endregion
}
#endif
